package com.face.task;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;


@Component
public class SchedulTask {

    @Value("${wechat.regaturl}")
    String regaturl;

    private static String accesstoken = "";

    /**
     * 定时刷新微信普通access_token
     */
    @Scheduled(fixedDelayString = "${jobs.fixedDelay}")
    public void refershregularAccessToken() {

        RestTemplate restTemplate = new RestTemplate();
        String json = restTemplate.getForObject(regaturl
                , String.class);

        Map<String, String> map = JSON.parseObject(json, HashMap.class);
        this.accesstoken = map.get("access_token");
//        System.out.println(map);
    }

    public static String getAccesstoken() {
        return accesstoken;
    }
}
